<template>
    <div>
      <ul>
        <li v-for="(item,index) in expData" :key="index">
          <img @click="menav(item)" :src="item.image" alt="数据加载失败">
          <div @click="menav(item)" class="e_center">
            <p>{{item.true_name}}</p>
            <p>{{item.signature}}</p>
            <p>领域：{{item.territory}}</p>
          </div>
          <span @click="follow(item)">{{item.status==0?'+ 关注':'已关注'}}</span>
        </li>
      </ul>

      <transition name="van-slide-right">
        <div v-show="visible" class="tran_right">{{Fade}}</div>
      </transition>

    </div>
</template>

<script>
  import * as search from "../../../api/search.js"
    export default {
      name: "Expert",
      data(){
        return {
          Fade:'',
          visible:false,
          expData:[]
        }
      },
      beforeMount(){
        let parms2 = {type:2,user_id:this.$store.state.user_id};
        search.userSearch(parms2).then(res=>{
          //console.log('达人',res);
          this.expData = res.data;
        });
      },
      mounted(){
        mui.back = function() {
          window.history.go(-1);
        }
      },
      methods:{
        menav(item){
          this.$router.push({
            path: '/menav',
            query:{
              id:item.id
            }
          })
        },
        follow(item){
          if (item.status==0){
            item.status = 1;
            let flow = {follow_id:item.id,user_id:this.$store.state.user_id,status:1};
            search.follow(flow).then(res=>{
              //console.log(res);
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            });
            search.followed(flow).then(res=>{
              //console.log(res);
            })
          } else{
            item.status = 0;
            let flow = {follow_id:item.id,user_id:this.$store.state.user_id,status:0};
            search.follow(flow).then(res=>{
              this.visible = true;
              this.Fade = res.msg;
              setTimeout(() => {
                this.visible = false;
              }, 500);
            });
            search.followed(flow).then(res=>{
              //console.log(res);
            })
          }
        }
      }
    }
</script>

<style scoped>
  ul li{
    display: flex;
    justify-content: space-between;
    padding: 20px 40px;
    border-bottom: 2px solid #dcdcdc;
  }
  ul li:last-child{
    border-bottom: none;
  }
  ul li img{
    background: #dcdcdc;
    width: 130px;
    height: 130px;
    border-radius: 50%;
  }
  ul li .e_center{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 55%;
  }
  ul li .e_center p{
    font-size: 32px;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
  ul li .e_center p:nth-child(2){
    font-size: 24px;
  }
  ul li>span{
    width: 120px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    border-radius: 10px;
    border: 2px solid #884ca4;
    color: #884ca4;
    font-size: 24px;
  }
  .tran_right{
    width: 220px;
    height: 60px;
    border-radius: 10px;
    text-align: center;
    line-height: 60px;
    font-size: 30px;
    top: 50%;
    left: 50%;
    position: fixed;
    background: rgba(0,0,0,0.6);
    color: #fff;
  }
</style>
